package com.springboot.example.monitor.util;

import com.springboot.example.monitor.domain.model.SendRequest;
import org.springframework.beans.factory.annotation.Value;

/**
 * 作者: guo yao
 * 日期: 2016年02月25日
 * 时间: 下午14:59
 */
public class WeixinUtils {

    @Value("${weixin.send.appid}")
    public static String send_app_id = "0";

    @Value("${weixin.send.corpurl}")
    public static String send_corp_url = "http://bee.breadenglish.com/enterprise/service/message_send";

    // 发送消息到企业号

    public void normal() throws Exception {
//        SendRequest sendRequest = new SendRequest();
//        sendRequest.setAppId("0");
//        sendRequest.setContext(errMessage.toString());
//        sendRequest.setToUser(manager);
//        String outputStr = JSONObject.fromObject(sendRequest).toString();
//        String send_url = "http://bee.breadenglish.com/enterprise/service/message_send";
//        JSONObject jsonObject = WechatClient.http(send_url, "POST", outputStr);
        SendRequest sendRequest = new SendRequest();
        sendRequest.setAppId("0");
        sendRequest.setContext("测试");
        sendRequest.setToUser("yao.guo");
        String outputStr = JacksonObjectMapper.getInstance().writeValueAsString(sendRequest);
        String url = "http://bee.breadenglish.com/enterprise/service/message_send";
        String result = HttpUtils.sendHttpRequest(url, "POST", outputStr);
        System.out.println("result:=" + result);

    }

    public static void main(String[] args) throws Throwable {
        WeixinUtils wu = new WeixinUtils();
        wu.normal();
    }

    /**
     * 发送企业号信息
     *
     * @param userId
     * @param message
     * @throws Exception
     */
    public static void sendWeixinInfo(String userId, String message) throws Exception {
        SendRequest sendRequest = new SendRequest();
        sendRequest.setAppId(send_app_id);
        sendRequest.setToUser(userId);
        sendRequest.setContext(message);
        String outputStr = JacksonObjectMapper.getInstance().writeValueAsString(sendRequest);
        HttpUtils.sendHttpRequest(send_corp_url, "POST", outputStr);
    }

}
